import org.apache.commons.dbcp2.BasicDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Practice_DBCP {
    public static void main(String[] args) {
        BasicDataSource basicDataSource = new BasicDataSource();
        basicDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        basicDataSource.setUrl("jdbc:mysql://localhost:3306/manger");
        basicDataSource.setUsername("root");
        basicDataSource.setPassword("");
        try {
            Connection connection = basicDataSource.getConnection();
            System.out.println(connection);
            PreparedStatement statement = connection.prepareStatement("select * from account");
            ResultSet resultSet = statement.executeQuery();
            while (resultSet.next()){
                int id = resultSet.getInt("id");
                double balance = resultSet.getDouble("balance");
                String commit  = resultSet.getString("commit");
                System.out.println("编号：" + id + ",余额：" + balance + ",备注：" + commit);
            }
            resultSet.close();
            statement.close();
            connection.close();
            basicDataSource.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
